#!/bin/bash

# 前端构建脚本

echo "=========================================="
echo "  文件同步器 - 前端构建"
echo "=========================================="
echo ""

# 进入前端目录
cd web

# 检查 node_modules
if [ ! -d "node_modules" ]; then
    echo "📦 安装前端依赖..."
    npm install
    if [ $? -ne 0 ]; then
        echo "❌ 依赖安装失败"
        exit 1
    fi
    echo "✅ 依赖安装完成"
    echo ""
fi

# 构建前端
echo "🔨 开始构建前端（生产环境）..."
NODE_ENV=production npm run build

if [ $? -eq 0 ]; then
    echo ""
    echo "=========================================="
    echo "✅ 前端构建成功！"
    echo "=========================================="
    echo ""
    echo "📦 构建文件位置: web/dist/"
    echo ""
    ls -lh dist/ | head -10
    echo ""
    echo "💡 下一步: 运行 ./package-for-deployment.sh 打包部署文件"
else
    echo ""
    echo "❌ 前端构建失败，请查看错误信息"
    exit 1
fi
